//卡务管理
angular.module('SmartCanteenApp.cardManage', ['ngRoute', 'ngTouch'])

    .config(['$routeProvider', function ($routeProvider) {
        $routeProvider.when('/cardManage', {
            templateUrl: 'cardManage/cardManage.html',
            controller: 'cardManageCtrl'
        });
         $routeProvider.when('/cardManage2', {
            templateUrl: 'cardManage/cardManage2.html',
            controller: 'cardManage2Ctrl'
        });
        $routeProvider.when('/consumeRecordManage', {
            templateUrl: 'cardManage/consumeRecordManage.html',
            controller: 'consumeRecordmanageCtrl'
        });
        $routeProvider.when('/operationRecord/:cardNo', {
            templateUrl: 'cardManage/operationRecord.html',
            controller: 'operationRecordCtrl'
        });
         $routeProvider.when('/businessCollect', {
            templateUrl: 'cardManage/businessCollect.html',
            controller: 'businessCollectCtrl'
        });
        $routeProvider.when('/mealCardAudit', {
            templateUrl: 'cardManage/mealCardAudit.html',
            controller: 'mealCardAuditCtrl'
        });
        $routeProvider.when('/mealCardType', {
            templateUrl: 'cardManage/mealCardType.html',
            controller: 'mealCardTypeCtrl'
        });
    }])

    .controller('cardManageCtrl', ['$scope', '$timeout','$routeParams', function ($scope, $timeout,$routeParams) {
    	$(".modal-dialog").draggable();//为模态对话框添加拖拽
        $(".modal").css("overflow", "hidden");//禁止模态对话框的半透明背景滚动
			$scope.myNo = 'vid200000000001';//暂时随便变动的卡号2017-05-25 10001  333333 
//			$scope.cardInfor = $scope.myNo ;
			//日历选择
			$('#datepicker').datepicker({
			  autoclose: true
			});
			$('#datepicker3').datepicker({
			  autoclose: true
			});
			//卡种对应的押金、工本费
//			$scope.card_cost = { '卡类1':{'depositCost':'20','bookCost':'10'},
//							'卡类2':{'depositCost':'50','bookCost':'20'} 
//							};
	
			//查询卡型信息，单卡操作时需要?debug=true
			var cardType= {"terminalId":10020001,"opName":"gly"};
    		$scope.getJson($scope.tianjinPath+'/query/cardkind',$scope.encrypt(cardType),"POST",function(data){
	   			console.log(data);
	   			$scope.cardTypes = data.content;
	   			$scope.cardKindId = $scope.cardTypes[0].cardKindId ;
	   			$scope.deposit = $scope.cardTypes[0].deposit ; //对应押金
	   			$scope.cardFee = $scope.cardTypes[0].cardFee ;//对应工本费
	   		});
	   		//查询卡务信息方法
	    	$scope.getCardInfors = function(){
	    		$scope.cardInformations = [];
	    		//进入页面自动查询卡务信息(所有卡信息是从我们的接口调，他们的接口目前是调单个卡信息的)
	  	 		var mydate = {"terminalId":10020001,"opName":"gly","cardNo":$scope.myNo};//vid200000000001//10001//22222,"name":$scope.myName
	    		$scope.getJson($scope.tianjinPath+'/query/card',$scope.encrypt(mydate),"POST",function(data){
		   			console.log(data);
		   			if( data.code == 200){
		   				//$scope.showSuccess('查询成功！');
		   				$scope.cardInformations = data.content;
		   				$scope.cardInformations[0].cardNo = $scope.myNo ;
		   			}else if(data.code == 40000){
		   				$scope.showError(data.msg);
		   			}else if(data.msg.indexOf('cardNo or name or mobile any one must not be null') != -1){
		   				$scope.showError('当前版本请输入卡号后，再点击查询');
		   			}
		   			//调用数据分页
					$scope.pagination($scope.cardInformations);		
		   		});
	    	}
			//支付方式
			$scope.payWays = [
								{'id':'10401','name':'现金'},
								{'id':'10405','name':'银行卡'},
								{'id':'10420','name':'微信'},
								{'id':'10425','name':'支付宝'},
							];
			$scope.payWay = $scope.payWays[0].id ;
			//点击查询
			$scope.search = function(){
				$scope.myNo = $scope.cardInfor.concat();
				$scope.getCardInfors();
			}
			//开卡时默认值
			$scope.sendPayment = 0;
			$scope.sendCardBalance = parseInt($scope.sendPayment) - parseInt($scope.depositCost) -parseInt($scope.bookCost) ;
			//选择卡型时，卡内余额随之变动
			$scope.cardKindChange = function(event){
				var arr = $scope.cardTypes;
				for(var i = 0; i<arr.length ; i ++){
					if(arr[i].cardKindId == $scope.cardKindId){
						$scope.deposit = arr[i].deposit ;
						$scope.cardFee = arr[i].cardFee ;
					}
				}
				$scope.sendCardBalance = parseInt($scope.sendPayment) - parseInt($scope.deposit) -parseInt($scope.cardFee) ;
			}
			 //填写开卡交款时，卡内余额随着变的方法
           $scope.Calculate = function(){
           		$scope.sendCardBalance = parseInt($scope.sendPayment) - parseInt($scope.deposit) -parseInt($scope.cardFee) ;
           }
			//选中某行后获取该行信息
			$scope.itemSelected = function(event,cardKindId){
	    		event.stopPropagation();
	    		//将数据展示区域的所有td背景颜色先去掉
	    		var allTd = document.getElementById('dataList').getElementsByTagName('td');
	    		for(var i = 0;i< allTd.length ; i++ ){
	    			allTd[i].className = '';
	    		}
	    		//保证js点击锁定的是tr标签
	    		var target = event.target ;
	    		if( target.nodeName == 'TD'){
	    			target = target.parentNode ;
	    		}
	    		var p = target.children ;
	    		for(var i = 0;i< p.length ; i++ ){
	    			p[i].className = 'selected';
	    		}
	    		$scope.chooseCardNo = $scope.myNo;//卡号（暂时写死）
	    		$scope.chooseCardKindName = p[1].innerHTML;//卡类型名称
	    		console.log($scope.cardTypes);
	    		console.log(cardKindId);
	    		//卡类型对应的押金、工本费
				var arr = $scope.cardTypes ;
				for(var i = 0; i< arr.length ;i++){
					if(arr[i].cardKindId == cardKindId){
						$scope.depositCost  = arr[i].deposit ;//押金
	    				$scope.bookCost  = arr[i].cardFee ; //工本费
					}
				}
	    		$scope.chooseName = p[2].innerHTML;//姓名
	    		$scope.chooseMobile = p[3].innerHTML;//手机号
	    		$scope.chooseJoinTime = p[4].innerHTML;//发卡时间
	    		$scope.chooseUserMoney = p[5].innerHTML;//充值金额
	    		$scope.choosePerMoney = p[6].innerHTML;//餐补金额
	    		$scope.chooseDeposit = p[7].innerHTML;//透支金额
//	    		$scope.chooseOffMoney = p[8].innerHTML;//优惠金额
	    		$scope.chooseCardStatus = p[8].innerHTML;//状态
    	}
    	//调用数据分页,先设置为空
			$scope.pagination([]);
    	$scope.initial = '10';
    	$scope.cardKind = '全部饭卡类型';
		$scope.cardInformations = [];
    	 //单卡发卡按钮
           $scope.sendCard = function(event){	
        	   event.stopPropagation();
        	   /* alert("准备发卡，发卡ID"+id); */
        	   $("#sendOneCard").modal('toggle')
        	   $scope.sendCardNo = ''; $scope.sendCardKind = '卡类1'; $scope.sendCardName = ''; $scope.sendCardPhone = ''; 
        	   $scope.sendPayment = 0; $scope.sendCardpaymentType = '现金';$scope.paymentPassword = '';$scope.validDate = '';
        	   $scope.sendCardBalance = parseInt($scope.sendPayment) - parseInt($scope.deposit) -parseInt($scope.cardFee) ;
           }
           //餐卡卡号，后期应该是在机器上刷卡获取，目前先随机获取
           //$scope.ctCardNo = parseInt( 1000000*Math.random() + 1 );
           $scope.uuid = function() {
			    var s = [];
			    var hexDigits = "0123456789abcdef";
			    for (var i = 0; i < 36; i++) {
			        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
			    }
			    s[14] = "4";  // bits 12-15 of the time_hi_and_version field to 0010
			    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);  // bits 6-7 of the clock_seq_hi_and_reserved to 01
			    s[8] = s[13] = s[18] = s[23] = "-";
			 
			    var uuid = s.join("");
			    return uuid;
			}
           //$scope.ctCardNo = $scope.uuid();
           //$scope.idCardNo = $scope.uuid();//芯片卡号
           $scope.sendCardPhone = '';//默认手机号为空
           	//发卡页确定按钮
   			$scope.sendCard_true = function(){
   				if( isNull($scope.ctCardNo) == true){
	           			$scope.showError('餐卡卡号不能为空');
	           			return;
	           		}
   				if( isNull($scope.sendCardName) == true){
	           			$scope.showError('用户姓名不能为空');
	           			return;
	           		}
// 				if( isNull($scope.sendCardPhone) == true){
//	           			$scope.showError('用户手机不能为空');
//	           			return;
//	           		}
//         		if( checkMobile($scope.sendCardPhone) == false){
//         			$scope.showError('手机号码不正确');
//         			return;
//         		}
           		if( isNull($scope.sendPayment) == true){
           			$scope.showError('开卡交款不能为空');
           			return;
           		}
           		if( $scope.sendPayment < 0   ){
           			$scope.showError('开卡交款不能小于0');
           			return;
           		}
           		if( $scope.sendCardBalance < 0   ){
           			$scope.showError('卡内余额不能小于0');
           			return;
           		}
// 				if( isNull($scope.paymentPassword) == true){
//         			$scope.showError('支付密码不能为空');
//         			return;
//         		}
   				var mydate = {
			           		"terminalId": 10020001,//终端号
							"opName": "gly",//操作人姓名
							"cardKindId": $scope.cardKindId,//卡型id
							"ctCardNo": $scope.ctCardNo,//餐卡卡号$scope.myNo
							"idCardNo":  $scope.ctCardNo,//芯片卡号$scope.myNo
							"name": $scope.sendCardName,
							"mobile": $scope.sendCardPhone,
							"money": $scope.sendPayment,//开卡交款
							"deposit": $scope.deposit,//押金
							"cardFee": $scope.cardFee,//工本费
							"payWay": $scope.payWay,//付款方式
							"cardPassword": $scope.paymentPassword,//支付密码
							"validEnd": $scope.validDate //有效期至
						};
						console.log(mydate);
		    		$scope.getJson($scope.tianjinPath+'/recharge/card/sale',$scope.encrypt(mydate),"POST",function(data){
			   			console.log(data);
						if(data.code == 200){
							 $("#sendOneCard").modal('toggle');
							 $scope.showSuccess('操作成功！');
							 $scope.myNo = $scope.ctCardNo.concat();
							  //重新查询卡务信息
							 $scope.getCardInfors();
						}else{
							$scope.showError(data.msg);
						}
			   		});
   			}
           //卡状态汇总
           $scope.status = {'12510':'激活','12520':'挂失','12540':'已退卡',};
           //单卡充值按钮
           $scope.recharge = function(event){	
        	   event.stopPropagation();
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   $("#reChargeOneCard").modal('toggle')
        	    //$scope.reChargeAmount = ''; $scope.recharge_payType = '现金'; $scope.reCharge_remarks = '';
           }
           //单卡充值页确定按钮
   			$scope.reCharge_true = function(){
   				var mydate =  {
					            "terminalId": 10020001,
								"opName": "gly",
								"cardNo": $scope.myNo,
								"chargeMoney": $scope.reChargeAmount,//充值金额
								"payWay": $scope.payWay,
								"remarks": $scope.reCharge_remarks
							};
   				console.log(mydate);
   				$scope.getJson($scope.tianjinPath+'/recharge/card/recharge',$scope.encrypt(mydate),"POST",function(data){
		   			console.log(data);
					if(data.code == 200){
						 $scope.showSuccess('操作成功！');
						 $("#reChargeOneCard").modal('toggle');
						 //重新查询卡务信息
						 $scope.getCardInfors();
					}else{
						$scope.showError(data.msg);
					}
		   		});
   			}
           //点击跳转此卡的操作记录
           $scope.goToOperationRecord = function(){
           	 	event.stopPropagation();
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
           		
           		$scope.jump('/operationRecord/'+$scope.chooseCardKindId);
           }
           //单卡退卡按钮
           $scope.backCard = function(event){	
        	   event.stopPropagation();
        	   $scope.backcardNo = $scope.myNo ;
        	   $scope.payWay = $scope.payWays[0].id ;
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   $("#backOneCard").modal('toggle')
        	   $scope.chargeMoney ='';$scope.deposit ='';$scope.cardFee ='';$scope.backRemark='';
           }
           //退卡页确定按钮（下面的  付款方式  / 操作备注  的字段不应该有吧）
   			$scope.backOneCard_true = function(){
   				var mydate =  {
					            "terminalId": 10020001,
								"opName": "gly",
								"cardNo": $scope.myNo,
								"payWay": $scope.payWay,//退款方式
								"remarks": $scope.backRemark,//操作备注
								"chargeMoney": $scope.chargeMoney,//退款本金
								"deposit":  $scope.deposit,//退款押金
								"cardFee":  $scope.cardFee//退款工本费
							};
   				console.log(mydate);
   				$scope.getJson($scope.tianjinPath+'/manager/card/refund',$scope.encrypt(mydate),"POST",function(data){
		   			console.log(data);
					if(data.code == 200){
						 $("#backOneCard").modal('toggle');
						 //重新查询卡务信息
						 $scope.getCardInfors();
					}else{
						$scope.showError(data.msg);
					}
		   		});
   			}
            //单卡挂失按钮
           $scope.checkIn = function(event){	
        	   event.stopPropagation();
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   if( $scope.chooseCardStatus == '挂失'){
        	   		$('#contentHtml').html('此卡已为挂失状态');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   $scope.guashiUsername
        	   //首先判断状态，如果已经是挂失状态，则提示此卡已挂失（显示已挂失页面），并return
        	   $("#checkIn").modal('toggle')
           }
          //单卡挂失页确定按钮
   			$scope.checkIn_true = function(){
   				var mydate =  {
					            "terminalId": 10020001,
								"opName": "gly",
								"cardNo": $scope.myNo,
								"type": "LOST",//挂失
							};
   				$scope.getJson($scope.tianjinPath+'/manager/card/lost',$scope.encrypt(mydate),"POST",function(data){
		   			console.log(data);
					if(data.code == 200){
						 $("#checkIn").modal('toggle');
						 $scope.showSuccess('操作成功！');
						 //重新查询卡务信息
						 $scope.getCardInfors();
					}else{
						$scope.showError(data.msg);
					}
		   		});
   			}
           //单卡激活按钮
           $scope.checkOut = function(event){	
        	   event.stopPropagation();
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   if( $scope.chooseCardStatus == '激活'){
        	   		$('#contentHtml').html('此卡已为激活状态');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   //首先判断状态，如果不是挂失状态，则提示此卡不可激活（显示已激活页面），并return
        	   $("#checkOut").modal('toggle')	
           }
            //单卡激活页确定按钮
   			$scope.checkOut_true = function(){
				var mydate =  {
					            "terminalId": 10020001,
								"opName": "gly",
								"cardNo": $scope.myNo,
								"type": "UNLOST",//解挂
							};
   				console.log();
   				$scope.getJson($scope.tianjinPath+'/manager/card/lost',$scope.encrypt(mydate),"POST",function(data){
		   			console.log(data);
					if(data.code == 200){
						 $("#checkOut").modal('toggle');
						 $scope.showSuccess('操作成功！');
						 //重新查询卡务信息
						 $scope.getCardInfors();
					}else{
						$("#checkOut").modal('toggle')
						$scope.showError(data.msg);
					}
		   		});
   			}
   			//补卡中的押金处理方式
   			$scope.dealTypes = [
   							{'id':'0','name':'重新收取押金'},
   							{'id':'1','name':'老卡押金转新卡'}
   							];
   			$scope.dealTypeId = $scope.dealTypes[0].id;
           //单卡补卡按钮
           $scope.replaceCard = function(event){	
           		$scope.chooseCardNo = $scope.myNo ;
        	   event.stopPropagation();
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   $("#replaceCard").modal('toggle')	
//      	   $scope.depositDealType = '方式1';$scope.paymentType = '现金';
        	   $scope.newCardId = '';$scope.expense = '';$scope.reissueRemark = '';
           }
           //单卡补卡页面确定按钮
   			$scope.replaceCard_true = function(){
   				var mydate =  {
					           "terminalId": 10020001,
								"opName": "gly",
								"oldIdCardNo": $scope.chooseCardNo,
								"newIdCardNo": $scope.newIdCardNo,//芯片卡号
								"newCtCardNo":  $scope.newCtCardNo,//卡面卡号
								"depositType": $scope.dealTypeId,//押金处理方式
								"cardFee": $scope.cardFee,//工本费
								"payWay": $scope.payWay,//付款方式
								"remarks": $scope.reissueRemark,//备注
							};
   				console.log(mydate);
   				$scope.getJson($scope.tianjinPath+'/manager/card/reissue',$scope.encrypt(mydate),"POST",function(data){
		   			console.log(data);
					if(data.code == 200){
						 $("#replaceCard").modal('toggle');
						 //重新查询卡务信息
						 $scope.getCardInfors();
					}else{
						$("#checkOut").modal('toggle')
						$scope.showError(data.msg);
					}
		   		});
   			}
            //单卡修改按钮
           $scope.modifyOneCard = function(event){	
        	   event.stopPropagation();
        	   $scope.modifyCardNo = $scope.myNo ;
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   //显示、隐藏窗口
        	   $("#modifyOneCard").modal('toggle')	
        	   $scope.updateCardoldPassword = '';$scope.updateCardNewPassword = '';$scope.updateCardDate = '';
           }
           //单卡修改页确定按钮
   			$scope.modifyOneCard_true = function(){
   				var mydate =  {
					            "terminalId": 10020001,
								"opName": "gly",
								"cardNo": $scope.myNo,
								"name": $scope.chooseName,
								"mobile": $scope.chooseMobile,
								"oldPassword": $scope.updateCardoldPassword,
								"newPassword": $scope.updateCardNewPassword,
								"validEnd": $scope.updateCardDate,
							};
							console.log(mydate);
   				$scope.getJson($scope.tianjinPath+'/manager/card/modify',$scope.encrypt(mydate),"POST",function(data){
		   			console.log(data);
					if(data.code == 200){
						 $("#modifyOneCard").modal('toggle');
						  $scope.showSuccess('操作成功！');
						 //重新查询卡务信息
						 $scope.getCardInfors();
					}else{
						$scope.showError(data.msg);
					}
		   		});
   			}
            //单卡提现按钮
           $scope.reflectOneCard = function(event){	
           		$scope.serialno = 'CTPOS358220170525160107347';
           		$scope.chooseCardNo = $scope.myNo ;
        	   event.stopPropagation();
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   //首先判断状态，如果不是挂失状态，则提示此卡不可激活（显示已激活页面），并return
        	   $("#reflectOneCard").modal('toggle')	
        	   $scope.money = '';
           }
            //提现页确定按钮
   			$scope.reflectOneCard_true = function(){
   				var mydate =  {
					            "terminalId": 10020001,
								"opName": "gly",
								"cardNo": $scope.myNo,
								"money": $scope.money,
								"serialno": $scope.serialno//目前流水号是现生成的，写死的，后期询问怎么取
							};
   				console.log(mydate);
   				$scope.getJson($scope.tianjinPath+'/accounts/withdrawal',$scope.encrypt(mydate),"POST",function(data){
		   			console.log(data);
					if(data.code == 200){
						 $("#reflectOneCard").modal('toggle');
						  $scope.showSuccess('操作成功！');
						 //重新查询卡务信息
						 $scope.getCardInfors();
					}else{
						$scope.showError(data.msg);
					}
		   		});
   			}
           //单卡核减、核加按钮
           $scope.kind ='reduce';
           $scope.addAndReduce = function(kind,event){	
        	   event.stopPropagation();
        	   $scope.chooseCardNo = $scope.myNo ;
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   $scope.kind= kind;
        	   if( kind == 'reduce'){
        	   		document.getElementById('addAndReduceTitle').innerHTML = '核减';
        	   		document.getElementById('addAndReduce_reduce').innerHTML = '余额核减金额';
        	   		document.getElementById('addAndReduce_add').innerHTML = '餐补核减金额';
        	   }else{
        	   	    document.getElementById('addAndReduceTitle').innerHTML = '核加';
        	   	    document.getElementById('addAndReduce_reduce').innerHTML = '余额核加金额';
        	   	    document.getElementById('addAndReduce_add').innerHTML = '餐补核加金额';
        	   }
        	   $("#addAndReduceOneCard").modal('toggle')
        	   $scope.rechargeBalance = '';$scope.subsidyBalance = '';$scope.remark = '';
        	   $scope.rechargeBalance = 0;$scope.subsidyBalance = 0;
           }
           //核减核加页面确定按钮
           $scope.addAndReduce_true = function(){
//         		//提示那边的后台，添加操作类型标识（到底是核减还是核加的标识）
           		if( $scope.kind == 'reduce'){
           			$scope.opType = '1';
           		}else{
           			$scope.opType = '0';
           		}
				var mydate =  {
					            "terminalId": 10020001,
								"opName": "gly",
								"cardNo": $scope.myNo,
								"opType": $scope.opType,
								"chargeMoney": $scope.rechargeBalance,
								"perMoney": $scope.subsidyBalance,
								"remarks": $scope.remark
							};
   				console.log(mydate);
   				$scope.getJson($scope.tianjinPath+'/accounts/modify',$scope.encrypt(mydate),"POST",function(data){
		   			console.log(data);
					if(data.code == 200){
						$scope.showSuccess('操作成功！');
						 $("#addAndReduceOneCard").modal('toggle');
						 //重新查询卡务信息
						 $scope.getCardInfors();
					}else{
						$scope.showError(data.msg);
					}
		   		});
   			}
           //实时监控搜索框的值
//          $scope.$watch('cardInfor',  function() {
//          	if($scope.cardInfor ==undefined){
//          		$scope.cardInfor = '';
//          	}
//		           //准备一个空的数组
//		           var newList = [];
//		           var arr = $scope.cardInformations ;
//		           var length = arr.length;
//		           if($scope.cardKind =='全部饭卡类型' ){
//			           	for(var i=0;i<length;i++){
//							if( arr[i].cardKindId.indexOf($scope.cardInfor) >= 0 ||arr[i].name.indexOf($scope.cardInfor) >= 0 ||arr[i].mobile.indexOf($scope.cardInfor) >= 0  ){
//								newList.push(arr[i]);
//							}
//			           }
//		           }else{
//			           	for(var i=0;i<length;i++){
//							if(  (arr[i].cardKindId.indexOf($scope.cardInfor) >= 0 ||arr[i].name.indexOf($scope.cardInfor) >= 0 ||arr[i].mobile.indexOf($scope.cardInfor) >= 0 )
//								  && arr[i].kindName == $scope.cardKind	){
//								newList.push(arr[i]);
//							}
//			           }
//		           }
//		           $scope.pagination(newList);
//          });
            //实时监控饭卡类型cardKind
            $scope.$watch('cardKind',  function() {
            	if($scope.cardInfor ==undefined){
            		$scope.cardInfor = '';
            	}
		           //准备一个空的数组
		           var newList = [];
		           var arr = $scope.cardInformations ;
		           var length = arr.length;
		           if($scope.cardKind =='全部饭卡类型' ){
			           	for(var i=0;i<length;i++){
							if( arr[i].cardKindId.indexOf($scope.cardInfor) >= 0 ||arr[i].name.indexOf($scope.cardInfor) >= 0 ||arr[i].mobile.indexOf($scope.cardInfor) >= 0  ){
								newList.push(arr[i]);
							}
			           }
		           }else{
			           	for(var i=0;i<length;i++){
							if(  (arr[i].cardKindId.indexOf($scope.cardInfor) >= 0 ||arr[i].name.indexOf($scope.cardInfor) >= 0 ||arr[i].mobile.indexOf($scope.cardInfor) >= 0 )
								  && arr[i].kindName == $scope.cardKind	){
								newList.push(arr[i]);
							}
			           }
		           }
		           $scope.pagination(newList);
            });
    	
    }])
    
    .controller('cardManage2Ctrl', ['$scope', '$timeout','$routeParams', function ($scope, $timeout,$routeParams) {
    	
	    	$(".modal-dialog").draggable();//为模态对话框添加拖拽
	        $(".modal").css("overflow", "hidden");//禁止模态对话框的半透明背景滚动
			//日历选择
			$('#datepicker').datepicker({
			  autoclose: true
			});
			$('#datepicker3').datepicker({
			  autoclose: true
			});
			var allCardType = [{'id':'-1','name':'全部'}];
			//查询卡型信息
    		$scope.getJson($scope.zhaopath+'/localserv/v1/query/cardkind','',"GET",function(data){
	   			console.log(data);
	   			$scope.cardintialTypes = data.data;
	   			$scope.sendintialCardKindId = $scope.cardintialTypes[0].id;
	   			$scope.cardTypes = allCardType.concat(data.data);
	   			$scope.cardKindId = $scope.cardTypes[0].id ;
	   			$scope.deposit = $scope.cardTypes[0].deposit ; //对应押金
	   		});
	   		//查询卡务信息方法
//	    	$scope.getCardInfors = function(){
//	    		$scope.cardInformations = [];
//	    		$scope.getJson($scope.zhaopath+'/localserv/v1/query/card?idCardNo='+$scope.cardInfor,'',"GET",function(data){
//		   			console.log(data);
//		   			if( data.code == 0){
//		   				if(data.data.length == 0){
//		   					$scope.showError('未查询到相关信息');
//		   					return;
//		   				}
//		   				$scope.cardInformations = data.data;
//		   				$scope.items = data.data;
//		   			}else{
//		   				$scope.showError(data.msg);
//		   			}
//		   		});
//	    	}
	    	//进入页面，默认第1页
	    	$scope.cardInfor = '';//卡号
	    	$scope.myName = '';//姓名
	    	$scope.myPhone = '';//手机号
	    	$scope.pages = 5;
	    	$scope.page = 1 ;
	    	$scope.pageList = [1];
	    	$scope.selPage = 1;
	    	$scope.totalNums = 0;
	    	$scope.selectPage2 = function (page) {
					//不能小于1大于最大
					//if (page < 1 || page > $scope.pages) return;
					//最多显示分页数5
					if (page > 2) {
					//因为只显示5个页数，大于2页开始分页转换
					var newpageList = [];
					for (var i = (page - 3) ; i < ((page + 2) > $scope.pages ? $scope.pages : (page + 2)) ; i++) {
					newpageList.push(i + 1);
					}
					$scope.pageList = newpageList;
					}
					$scope.selPage = page;
					$scope.setData();
					$scope.isActivePage(page);
					console.log("选择的页：" + page);
					$scope.getAllCardInfors();
				};
			//设置当前选中页样式
			$scope.isActivePage2 = function (page) {
				return $scope.selPage == page;
			};
			//上一页
				$scope.Previous2 = function () {
					if( $.inArray($scope.selPage - 1, $scope.pageList) == -1 ){
						return;
					}
					$scope.selectPage2($scope.selPage - 1);
				}
				//下一页
				$scope.Next2 = function () {
					if( $.inArray($scope.selPage + 1, $scope.pageList) == -1 ){
						return;
					}
					$scope.selectPage2($scope.selPage + 1);
				};
	    	//查询所有卡务信息
	    	$scope.getAllCardInfors = function(){
	    		console.log($scope.cardInfor);
	    		console.log($scope.myName);
	    		console.log($scope.myPhone);
	    		console.log($scope.cardKindId);
	    		console.log($scope.selPage);
	    		$scope.cardInformations = [];
					var postData = {
		    			'cardChipNo':$scope.cardInfor,
						'userName':$scope.myName,
						'userPhone':$scope.myPhone,
						'cartTypeId': parseInt($scope.cardKindId) ,
						'currentPage':$scope.selPage,
		    		};	
				console.log(postData);
	    		$scope.getJson($scope.zhaopath+'/localserv/v1/query/card',postData,"POST",function(data){
		   			console.log(data);
		   			if( data.code == 0){
		   				if(data.data.length == 0){
		   					$scope.showError('未查询到相关信息');
		   					return;
		   				}
		   				$scope.totalNums = data.data.total ;
		   				$scope.pages = Math.ceil(data.data.total / 10 ); //分页数
						$scope.newPages = $scope.pages > 5 ? 5 : $scope.pages;
						$scope.pageList = [];
						//分页要repeat的数组
						for (var i = 0; i < $scope.newPages; i++) {
							$scope.pageList.push(i + 1);
						}
		   				$scope.cardInformations = data.data;
		   				$scope.items = data.data.result;
		   			}else{
		   				$scope.showError(data.msg);
		   			}
		   		});
	    	}
	    	$scope.getAllCardInfors();
			//点击查询
			$scope.search = function(){
				$scope.selPage = 1;
				//查询所有卡信息
				$scope.getAllCardInfors();
			}
			//开卡时默认值
			$scope.sendPayment = 0;
			$scope.sendCardBalance = parseInt($scope.sendPayment) - parseInt($scope.deposit)  ;//-parseInt($scope.bookCost)
			//选择卡型时，卡内余额随之变动
			$scope.cardKindChange = function(event){
				var arr = $scope.cardTypes;
				for(var i = 0; i<arr.length ; i ++){
					if(arr[i].id == $scope.sendintialCardKindId){
						$scope.deposit = arr[i].deposit ;
					}
				}
				$scope.sendCardBalance = parseInt($scope.sendPayment) - parseInt($scope.deposit)  ;//-parseInt($scope.cardFee)
			}
			 //填写开卡交款时，卡内余额随着变的方法
           $scope.Calculate = function(){
           		$scope.sendCardBalance = parseInt($scope.sendPayment) - parseInt($scope.deposit)  ;//-parseInt($scope.cardFee)
           }
			//选中某行后获取该行信息
			$scope.itemSelected = function(event,cardKindId){
	    		event.stopPropagation();
	    		//将数据展示区域的所有td背景颜色先去掉
	    		var allTd = document.getElementById('dataList').getElementsByTagName('td');
	    		for(var i = 0;i< allTd.length ; i++ ){
	    			allTd[i].className = '';
	    		}
	    		//保证js点击锁定的是tr标签
	    		var target = event.target ;
	    		if( target.nodeName == 'TD'){
	    			target = target.parentNode ;
	    		}
	    		if( target.nodeName == 'IMG'){
	    			target = target.parentNode.parentNode ;
	    		}
	    		var p = target.children ;
	    		for(var i = 0;i< p.length ; i++ ){
	    			p[i].className = 'selected';
	    		}
	    		$scope.chooseCardNo = p[0].innerHTML;//卡号（暂时写死）
	    		$scope.chooseCardKindName = p[1].innerHTML;//卡类型名称
	    		//卡类型对应的押金、工本费
				var arr = $scope.cardTypes ;
				for(var i = 0; i< arr.length ;i++){
					if(arr[i].cardKindId == cardKindId){
						$scope.depositCost  = arr[i].deposit ;//押金
					}
				}
	    		$scope.chooseName = p[2].innerHTML;//姓名
	    		$scope.chooseMobile = p[3].innerHTML;//手机号
	    		$scope.chooseJoinTime = p[4].innerHTML;//发卡时间
	    		$scope.chooseUserMoney = p[5].innerHTML;//余额
	    		$scope.chooseDeposit = p[6].innerHTML;//押金
	    		$scope.chooseCardStatus = p[7].innerHTML;//状态
	    		$scope.chooseidCardNo = p[8].innerHTML;//芯片卡号
	    		$scope.chooseid = p[9].innerHTML;//id
	    		$scope.balanceCount = p[10].innerHTML;//指纹剩余次数
	    		console.log($scope.chooseid);//id
	    		console.log($scope.balanceCount);
    	}
		//打开指纹录入模板
		$scope.openFinger = function(cardId,count){
			console.log(count);
			if( count == null ){
				$scope.fingerCount = '';
				$scope.finger_remarks = '';
				$("#openFinger").modal('toggle');
			}else{
				$scope.fingerCount = $scope.balanceCount
				$("#updateFingerCount").modal('toggle');
			}
		}
		//录入指纹确定键
		$scope.finger_true = function(){
			if( !isNull($scope.fingerInput) ){
				$scope.showError( '指纹信息获取失败' );
			}
			if( !isNumber($scope.fingerCount) ){
				$scope.showError( '请输入正整数' );
			}
			if( $scope.fingerCount <= 0 ){
				$scope.showError( '请输入正整数' );
			}
			var postData = {
				'csCardUserInfoId':$scope.chooseid,
				'fingerprintCode':$scope.fingerInput,
				'value':$scope.fingerCount,
				'remarks':$scope.finger_remarks,
			};
			$scope.getJson($scope.zhaopath+'/localserv/v1/open/fingerprint',postData,"POST",function(data){
		   			console.log(data);
		   			if( data.code == 0){
		   				 $scope.showSuccess('操作成功！');
		   				 $("#openFinger").modal('toggle');
		   				 //查询所有卡信息
						$scope.getAllCardInfors();
		   			}else{
		   				$scope.showError(data.msg);
		   			}
		   		});
		}
		//指纹消费次数添加
		$scope.countAdd_true = function(){
			console.log($scope.chooseid);
			console.log($scope.fingerCount);
			if( !isNumber($scope.fingerCount) ){
				$scope.showError( '请输入正整数' );
			}
			if( $scope.fingerCount <= 0 ){
				$scope.showError( '请输入正整数' );
			}
			var postData = {
				'csCardUserInfoId':$scope.chooseid,
				'value':$scope.fingerCount,
			};
			
			$scope.getJson($scope.zhaopath+'/localserv/v1/verification/fingerprint',postData,"POST",function(data){
		   			console.log(data);
		   			if( data.code == 0){
		   				 $scope.showSuccess('操作成功！');
		   				 $("#updateFingerCount").modal('toggle');
		   				 //查询所有卡信息
						$scope.getAllCardInfors();
		   			}else{
		   				$scope.showError(data.msg);
		   			}
		   		});
			
			
		}
		
		$scope.temps = [
					 {'id':'0','name':'是'}
					,{'id':'1','name':'否'}
		];
		$scope.tempId = $scope.temps[0].id;	
			
    	//调用数据分页,先设置为空
			$scope.pagination([]);
    	$scope.initial = '10';
    	$scope.cardKind = '全部饭卡类型';
		$scope.cardInformations = [];
    	 //单卡发卡按钮
           $scope.sendCard = function(event){	
        	   event.stopPropagation();
        	   /* alert("准备发卡，发卡ID"+id); */
        	   $("#sendOneCard").modal('toggle')
        	   $scope.ctCardNo = $scope.uuid(); //餐卡卡号
        	   $scope.idCardNo = $scope.uuid();//芯片卡号
	   		   $scope.sendintialCardKindId = $scope.cardintialTypes[0].id;//餐卡类型id
//      	   $scope.sendCardKindId = $scope.cardTypes[0].id ;//餐卡类型id
//      	   $scope.tempId = $scope.temps[0].id;//是否为临时卡
        	   $scope.sendCardName = '';//用户姓名 
        	   $scope.sendCardPhone = '';//用户手机
        	   $scope.sendPayment = 0;
//      	   $scope.payWay = $scope.payWays[0].id ;//支付方式
        	   $scope.deposit = $scope.cardintialTypes[0].deposit;//押金
//      	   $scope.paymentPassword = '';//支付密码
//      	   $scope.validDate = '';//有效期至
        	   $scope.sendCardBalance = parseInt($scope.sendPayment) - parseInt($scope.deposit) ;//卡内余额 -parseInt($scope.cardFee)
           }
           //餐卡卡号，后期应该是在机器上刷卡获取，目前先随机获取
           //$scope.ctCardNo = parseInt( 1000000*Math.random() + 1 );
           $scope.uuid = function() {
			    var s = [];
			    var hexDigits = "0123456789abcdef";
			    for (var i = 0; i < 36; i++) {
			        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
			    }
			    s[14] = "4";  // bits 12-15 of the time_hi_and_version field to 0010
			    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);  // bits 6-7 of the clock_seq_hi_and_reserved to 01
			    s[8] = s[13] = s[18] = s[23] = "-";
			 
			    var uuid = s.join("");
			    return uuid;
			}
            $scope.ctCardNo = $scope.uuid();//餐卡卡号
            $scope.idCardNo = $scope.uuid();//芯片卡号
            $scope.sendCardPhone = '';//默认手机号为空
           	//发卡页确定按钮
   			$scope.sendCard_true = function(){
   				if( isNull($scope.ctCardNo) == true){
	           			$scope.showError('餐卡卡号不能为空');
	           			return;
	           		}
   				if( isNull($scope.idCardNo) == true){
	           			$scope.showError('芯片卡号不能为空');
	           			return;
	           		}
   				if( isNull($scope.sendCardName) == true){
	           			$scope.showError('用户姓名不能为空');
	           			return;
	           		}
   				if( isNull($scope.sendCardPhone) == true){
	           			$scope.showError('用户手机不能为空');
	           			return;
	           		}
           		if( checkMobile($scope.sendCardPhone) == false){
           			$scope.showError('手机号码格式不正确');
           			return;
           		}
           		if( isNull($scope.sendPayment) == true){
           			$scope.showError('开卡交款不能为空');
           			return;
           		}
           		if( $scope.sendPayment < 0   ){
           			$scope.showError('开卡交款不能小于0');
           			return;
           		}
           		if( $scope.sendCardBalance < 0   ){
           			$scope.showError('卡内余额不能小于0');
           			return;
           		}
   				var mydate = {
							"cardNo": $scope.ctCardNo,//餐卡卡号$scope.myNo
							"cardChipNo":  $scope.ctCardNo,//芯片卡号$scope.myNo
							"cardTypeId": $scope.sendintialCardKindId,//餐卡类型
							"userName": $scope.sendCardName, //用户姓名
							"phone": $scope.sendCardPhone, //用户手机
							"value": $scope.sendPayment,//开卡交款
//							"deposit": $scope.deposit,//押金
//							"payWay": $scope.payWay,//付款方式
						};
						console.log(mydate);
		    		$scope.getJson($scope.zhaopath+'/localserv/v1/open/card',mydate,"POST",function(data){
			   			console.log(data);
						if(data.code == 0){
							 $("#sendOneCard").modal('toggle');
							 $scope.showSuccess('操作成功！');
//							 $scope.cardInfor = data.data.cardNo;
							  //重新查询卡务信息
							$scope.getAllCardInfors();
						}else{
							$scope.showError(data.msg);
						}
			   		});
   			}
//         //卡状态汇总
//         $scope.status = {'12510':'激活','12520':'挂失','12540':'已退卡',};
           //单卡充值按钮
           $scope.recharge = function(event){	
        	   event.stopPropagation();
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   $("#reChargeOneCard").modal('toggle')
        	    //$scope.reChargeAmount = ''; $scope.recharge_payType = '现金'; $scope.reCharge_remarks = '';
           }
           //单卡充值页确定按钮
   			$scope.reCharge_true = function(){
           			$scope.opType = 1;
				var mydate =  {
								"cardChipNo": $scope.chooseidCardNo,//芯片卡号
								"value": $scope.reChargeAmount,//变动金额
								"optType": $scope.opType,//操作类型
								"remark": $scope.reCharge_remarks//备注
							};
   				console.log(mydate);
   				$scope.getJson($scope.zhaopath+'/localserv/v1/verification/card',mydate,"POST",function(data){
		   			console.log(data);
					if(data.code == 0){
						$scope.showSuccess('操作成功！');
						$("#reChargeOneCard").modal('toggle')
						 //重新查询卡务信息
						$scope.getAllCardInfors();
					}else{
						$scope.showError(data.msg);
					}
		   		});
   			}
           //点击跳转此卡的操作记录
           $scope.goToOperationRecord = function(){
           	 	event.stopPropagation();
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
           		
           		$scope.jump('/operationRecord/'+$scope.chooseCardKindId);
           }
           //单卡退卡按钮
           $scope.backCard = function(event){	
        	   event.stopPropagation();
        	   $scope.backcardNo = $scope.chooseCardNo ;
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   $("#backOneCard").modal('toggle')
        	   $scope.chargeMoney ='';$scope.deposit ='';$scope.cardFee ='';$scope.backRemark='';
        	   $scope.retotal = parseFloat($scope.chooseUserMoney) + parseFloat($scope.chooseDeposit) ;
           }
           //退卡页确定按钮（下面的  付款方式  / 操作备注  的字段不应该有吧）
   			$scope.backOneCard_true = function(){
   				var mydate =  {
								"cardChipNo": $scope.backcardNo,
								"remark": $scope.backRemark,//操作备注
							};
   				console.log(mydate);
   				$scope.getJson($scope.zhaopath+'/localserv/v1/return/card',mydate,"POST",function(data){
		   			console.log(data);
					if(data.code == 0){
						 $("#backOneCard").modal('toggle');
						 $scope.showSuccess('操作成功！');
						 //重新查询卡务信息
						 $scope.getAllCardInfors();
					}else{
						$scope.showError(data.msg);
					}
		   		});
   			}
            //单卡挂失按钮
           $scope.checkIn = function(event){	
        	   event.stopPropagation();
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   if( $scope.chooseCardStatus == '挂失'){
        	   		$('#contentHtml').html('此卡已为挂失状态');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   $scope.guashiUsername
        	   //首先判断状态，如果已经是挂失状态，则提示此卡已挂失（显示已挂失页面），并return
        	   $("#checkIn").modal('toggle')
           }
          //单卡挂失页确定按钮
   			$scope.checkIn_true = function(){
   				var mydate =  {
					            "terminalId": 10020001,
								"opName": "gly",
								"cardNo": $scope.myNo,
								"type": "LOST",//挂失
							};
   				$scope.getJson($scope.tianjinPath+'/manager/card/lost',$scope.encrypt(mydate),"POST",function(data){
		   			console.log(data);
					if(data.code == 200){
						 $("#checkIn").modal('toggle');
						 $scope.showSuccess('操作成功！');
						 //重新查询卡务信息
						 $scope.getAllCardInfors();
					}else{
						$scope.showError(data.msg);
					}
		   		});
   			}
           //单卡激活按钮
           $scope.checkOut = function(event){	
        	   event.stopPropagation();
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   if( $scope.chooseCardStatus == '激活'){
        	   		$('#contentHtml').html('此卡已为激活状态');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   //首先判断状态，如果不是挂失状态，则提示此卡不可激活（显示已激活页面），并return
        	   $("#checkOut").modal('toggle')	
           }
            //单卡激活页确定按钮
   			$scope.checkOut_true = function(){
				var mydate =  {
					            "terminalId": 10020001,
								"opName": "gly",
								"cardNo": $scope.myNo,
								"type": "UNLOST",//解挂
							};
   				console.log();
   				$scope.getJson($scope.tianjinPath+'/manager/card/lost',$scope.encrypt(mydate),"POST",function(data){
		   			console.log(data);
					if(data.code == 200){
						 $("#checkOut").modal('toggle');
						 $scope.showSuccess('操作成功！');
						 //重新查询卡务信息
						 $scope.getAllCardInfors();
					}else{
						$("#checkOut").modal('toggle')
						$scope.showError(data.msg);
					}
		   		});
   			}
   			//补卡中的押金处理方式
   			$scope.dealTypes = [
   							{'id':'0','name':'重新收取押金'},
   							{'id':'1','name':'老卡押金转新卡'}
   							];
   			$scope.dealTypeId = $scope.dealTypes[0].id;
           //单卡补卡按钮
           $scope.replaceCard = function(event){	
           		$scope.chooseCardNo = $scope.myNo ;
        	   event.stopPropagation();
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   $("#replaceCard").modal('toggle')	
//      	   $scope.depositDealType = '方式1';$scope.paymentType = '现金';
        	   $scope.newCardId = '';$scope.expense = '';$scope.reissueRemark = '';
           }
           //单卡补卡页面确定按钮
   			$scope.replaceCard_true = function(){
   				var mydate =  {
					           "terminalId": 10020001,
								"opName": "gly",
								"oldIdCardNo": $scope.chooseCardNo,
								"newIdCardNo": $scope.newIdCardNo,//芯片卡号
								"newCtCardNo":  $scope.newCtCardNo,//卡面卡号
								"depositType": $scope.dealTypeId,//押金处理方式
								"cardFee": $scope.cardFee,//工本费
								"payWay": $scope.payWay,//付款方式
								"remarks": $scope.reissueRemark,//备注
							};
   				console.log(mydate);
   				$scope.getJson($scope.tianjinPath+'/manager/card/reissue',$scope.encrypt(mydate),"POST",function(data){
		   			console.log(data);
					if(data.code == 200){
						 $("#replaceCard").modal('toggle');
						 //重新查询卡务信息
						$scope.getAllCardInfors();
					}else{
						$("#checkOut").modal('toggle')
						$scope.showError(data.msg);
					}
		   		});
   			}
            //单卡修改按钮
           $scope.modifyOneCard = function(event){	
        	   event.stopPropagation();
        	   $scope.modifyCardNo = $scope.myNo ;
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   //显示、隐藏窗口
        	   $("#modifyOneCard").modal('toggle')	
        	   $scope.updateCardoldPassword = '';$scope.updateCardNewPassword = '';$scope.updateCardDate = '';
           }
           //单卡修改页确定按钮
   			$scope.modifyOneCard_true = function(){
   				var mydate =  {
					            "terminalId": 10020001,
								"opName": "gly",
								"cardNo": $scope.myNo,
								"name": $scope.chooseName,
								"mobile": $scope.chooseMobile,
								"oldPassword": $scope.updateCardoldPassword,
								"newPassword": $scope.updateCardNewPassword,
								"validEnd": $scope.updateCardDate,
							};
							console.log(mydate);
   				$scope.getJson($scope.tianjinPath+'/manager/card/modify',$scope.encrypt(mydate),"POST",function(data){
		   			console.log(data);
					if(data.code == 200){
						 $("#modifyOneCard").modal('toggle');
						  $scope.showSuccess('操作成功！');
						 //重新查询卡务信息
						 $scope.getAllCardInfors();
					}else{
						$scope.showError(data.msg);
					}
		   		});
   			}
            //单卡提现按钮
           $scope.reflectOneCard = function(event){	
           		$scope.serialno = 'CTPOS358220170525160107347';
//         		$scope.chooseCardNo = chooseCardNo ;
        	   event.stopPropagation();
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   //首先判断状态，如果不是挂失状态，则提示此卡不可激活（显示已激活页面），并return
        	   $("#reflectOneCard").modal('toggle')	
        	   $scope.money = '';
           }
            //提现页确定按钮
   			$scope.reflectOneCard_true = function(){
   				var mydate =  {
					            "terminalId": 10020001,
								"opName": "gly",
								"cardNo": $scope.myNo,
								"money": $scope.money,
								"serialno": $scope.serialno//目前流水号是现生成的，写死的，后期询问怎么取
							};
   				console.log(mydate);
   				$scope.getJson($scope.tianjinPath+'/accounts/withdrawal',$scope.encrypt(mydate),"POST",function(data){
		   			console.log(data);
					if(data.code == 200){
						 $("#reflectOneCard").modal('toggle');
						  $scope.showSuccess('操作成功！');
						 //重新查询卡务信息
						 $scope.getAllCardInfors();
					}else{
						$scope.showError(data.msg);
					}
		   		});
   			}
           //单卡核减、核加按钮
           $scope.kind ='reduce';
           $scope.addAndReduce = function(kind,event){	
        	   event.stopPropagation();
//      	   $scope.chooseCardNo = $scope.myNo ;
        	   var selectedTds = document.getElementsByClassName('selected');
        	   if( selectedTds.length <= 0){
        	   		$('#contentHtml').html('请选择一张餐卡');
					$('#warningChoose').modal('toggle');
					return;
        	   }
        	   $scope.kind= kind;
        	   if( kind == 'reduce'){
        	   		document.getElementById('addAndReduceTitle').innerHTML = '核减';
        	   		document.getElementById('addAndReduce_reduce').innerHTML = '余额核减金额';
        	   }else{
        	   	    document.getElementById('addAndReduceTitle').innerHTML = '核加';
        	   	    document.getElementById('addAndReduce_reduce').innerHTML = '余额核加金额';
        	   }
        	   $("#addAndReduceOneCard").modal('toggle');
        	   $scope.rechargeBalance = 0;
        	   $scope.remark = '';
        	  
           }
           //核减核加页面确定按钮
           $scope.addAndReduce_true = function(){
//         		//提示那边的后台，添加操作类型标识（到底是核减还是核加的标识）
           		if( $scope.kind == 'reduce'){
           			$scope.opType = 3;
           		}else{
           			$scope.opType = 2;
           		}
				var mydate =  {
								"cardChipNo": $scope.chooseidCardNo,//芯片卡号
								"value": $scope.rechargeBalance,//变动金额
								"optType": $scope.opType,//操作类型
								"remark": $scope.remark//备注
							};
   				console.log(mydate);
   				$scope.getJson($scope.zhaopath+'/localserv/v1/verification/card',mydate,"POST",function(data){
		   			console.log(data);
					if(data.code == 0){
						$scope.showSuccess('操作成功！');
						 $("#addAndReduceOneCard").modal('toggle');
						 //重新查询卡务信息
						 $scope.getAllCardInfors();
					}else{
						$scope.showError(data.msg);
					}
		   		});
   			}
            //实时监控饭卡类型cardKind
            $scope.$watch('cardKind',  function() {
            	if($scope.cardInfor ==undefined){
            		$scope.cardInfor = '';
            	}
		           //准备一个空的数组
		           var newList = [];
		           var arr = $scope.cardInformations ;
		           var length = arr.length;
		           if($scope.cardKind =='全部饭卡类型' ){
			           	for(var i=0;i<length;i++){
							if( arr[i].cardKindId.indexOf($scope.cardInfor) >= 0 ||arr[i].name.indexOf($scope.cardInfor) >= 0 ||arr[i].mobile.indexOf($scope.cardInfor) >= 0  ){
								newList.push(arr[i]);
							}
			           }
		           }else{
			           	for(var i=0;i<length;i++){
							if(  (arr[i].cardKindId.indexOf($scope.cardInfor) >= 0 ||arr[i].name.indexOf($scope.cardInfor) >= 0 ||arr[i].mobile.indexOf($scope.cardInfor) >= 0 )
								  && arr[i].kindName == $scope.cardKind	){
								newList.push(arr[i]);
							}
			           }
		           }
		           $scope.pagination(newList);
            });
    }])
   //消费记录管理
    .controller('consumeRecordmanageCtrl', ['$scope', '$timeout', function ($scope, $timeout) {
    	$(".modal-dialog").draggable();//为模态对话框添加拖拽
        $(".modal").css("overflow", "hidden");//禁止模态对话框的半透明背景滚动
    	$scope.cardKind ='全部类型';
    	//调用数据分页,先设置为空
			$scope.pagination([]);
			$scope.initial = '10';
    	//获取时间
        $scope.getNowFormatDate = function() {
		    var date = new Date();
		    var seperator1 = "-";
		    var seperator2 = ":";
		    var month = date.getMonth() + 1;
		    var strDate = date.getDate();
		    if (month >= 1 && month <= 9) {
		        month = "0" + month;
		    }
		    if (strDate >= 0 && strDate <= 9) {
		        strDate = "0" + strDate;
		    }
		    var now = date.getFullYear() + seperator1 + month + seperator1 + strDate;
		    
		    return now;
		}
			$('#reservation').daterangepicker();
			$scope.searchDate = $scope.getNowFormatDate()+' '+'至'+' '+$scope.getNowFormatDate();
		$scope.consumeInformations = [];
		//查询方法
		$scope.search = function(){
			//点击查询后展现消费信息
				$scope.consumeInformations = [
			        	{"expenseRecordId": '11',"expenseTime": "2016-05-20 19:49","username": "阿凡达","cardNo": "001","expenseType": "食堂消费", 
			            "expenseTotalMoney": 23,"expenseSubsidy": 7.5,"expenseRecharge": '0',"alterFlag": '0'},
						           ];
						//调用数据分页
						$scope.pagination($scope.consumeInformations);
		}
    	//修改标识替换码
    	$scope.alterFlagString = {'0':'未修改','1':'已修改','2':'多次修改'};
    	//显示修改页面
    	$scope.edit = function(consumeId,cardNo,userName,expenseType,expenseTime,expenseTotalMoney,expenseSubsidy,expenseRecharge){
    		console.log(consumeId);console.log(cardNo);console.log(userName);console.log(expenseType);console.log(expenseTime);
    		$scope.consumeId = consumeId;
    		$scope.cardNo = cardNo ;
    		$scope.userName = userName ;
    		$scope.expenseType = expenseType ;
    		$scope.expenseTime = expenseTime ;
    		$scope.expenseTotalMoney = expenseTotalMoney ;
    		$scope.expenseSubsidy = expenseSubsidy ;
    		$scope.expenseRecharge = expenseRecharge ;
    		
    		$('#editConsume').modal('toggle');
    	}
		//提示是否撤销消费记录
		$scope.del = function(expenseRecordId,cardNo,userName,expenseTime){
			console.log(expenseRecordId);console.log(cardNo);console.log(userName);console.log(expenseTime);
			$scope.consumeId = expenseRecordId;
    		$scope.cardNo = cardNo ;
    		$scope.userName = userName ;
    		$scope.expenseTime = expenseTime ;
			$('#cancelConsume').modal('toggle');
			
		}
		//实时监控搜索框的值
            $scope.$watch('cardInfor',  function() {
            	if($scope.cardInfor ==undefined){
            		$scope.cardInfor = '';
            	}
            	console.log($scope.cardInfor);
            	console.log($scope.cardKind);
		           //准备一个空的数组
		           var newList = [];
		           var arr = $scope.consumeInformations ;
		           var length = arr.length;
		           if($scope.cardKind =='全部类型' ){
			           	for(var i=0;i<length;i++){
							if( arr[i].cardNo.indexOf($scope.cardInfor) >= 0 ||arr[i].username.indexOf($scope.cardInfor) >= 0 ){
								newList.push(arr[i]);
							}
			           }
		           }else{
			           	for(var i=0;i<length;i++){
							if(  (arr[i].cardNo.indexOf($scope.cardInfor) >= 0 ||arr[i].username.indexOf($scope.cardInfor) >= 0 )
								  && arr[i].expenseType == $scope.cardKind	){
								newList.push(arr[i]);
							}
			           }
		           }
		           $scope.pagination(newList);
            });
            //实时监控饭卡类型cardKind
            $scope.$watch('cardKind',  function() {
            	if($scope.cardInfor ==undefined){
            		$scope.cardInfor = '';
            	}
            	console.log($scope.cardKind);
		           //准备一个空的数组
		           var newList = [];
		           var arr = $scope.consumeInformations ;
		           var length = arr.length;
		           if($scope.cardKind =='全部类型' ){
			           	for(var i=0;i<length;i++){
							if( arr[i].cardNo.indexOf($scope.cardInfor) >= 0 ||arr[i].username.indexOf($scope.cardInfor) >= 0 ){
								newList.push(arr[i]);
							}
			           }
		           }else{
			           	for(var i=0;i<length;i++){
							if(  (arr[i].cardNo.indexOf($scope.cardInfor) >= 0 ||arr[i].username.indexOf($scope.cardInfor) >= 0 )
								  && arr[i].expenseType == $scope.cardKind	){
								newList.push(arr[i]);
							}
			           }
		           }
		           $scope.pagination(newList);
            });
    }])
    
//操作记录
    .controller('operationRecordCtrl', ['$scope', '$timeout','$routeParams', function ($scope, $timeout,$routeParams) {
    	$(".modal-dialog").draggable();//为模态对话框添加拖拽
        $(".modal").css("overflow", "hidden");//禁止模态对话框的半透明背景滚动
    	$scope.cardInfor = '';//卡号
    	$scope.myName = '';//姓名
    	console.log($routeParams);
			$scope.route_cardNo = $routeParams.cardNo ;
			console.log($scope.route_cardNo);
			
			var allCardType = [{'key':'-1','name':'全部卡类型'}];
			var allopType = [{'key':'-1','name':'全部操作类型'}];
	   	//查询卡型信息
    		$scope.getJson($scope.zhaopath+'/localserv/v1/query/cardkind','',"GET",function(data){
	   			console.log(data);
	   			$scope.cardTypes = allCardType.concat(data.data);
	   			$scope.cardKindId = $scope.cardTypes[0].id ;
	   			$scope.deposit = $scope.cardTypes[0].deposit ; //对应押金
	   		});
    	//查询操作类型
    	$scope.getoperationTypes = function(){
    		$scope.getJson($scope.zhaopath+'/localserv/v1/query/cardopttype',{},"GET",function(data){
		   			console.log(data);
		   			if( data.code == 0){
		   				$scope.operationTypes = allopType.concat(data.data);
		   				$scope.operationTypeId = $scope.operationTypes[0].key;
		   			}else{
		   			}
		   		});
    	}
    	$scope.getoperationTypes();
    	//获取时间(年月日)
        $scope.getNowFormatDate = function() {
		    var date = new Date();
		    var seperator1 = "-";
		    var seperator2 = ":";
		    var month = date.getMonth() + 1;
		    var strDate = date.getDate();
		    if (month >= 1 && month <= 9) {
		        month = "0" + month;
		    }
		    if (strDate >= 0 && strDate <= 9) {
		        strDate = "0" + strDate;
		    }
		    var now = date.getFullYear() + seperator1 + month + seperator1 + strDate;
		    
		    return now;
		}
		$('#reservation').daterangepicker();
		$scope.searchDate = $scope.getNowFormatDate()+' '+'至'+' '+$scope.getNowFormatDate();
		
		$scope.operationRecordInfors = [];
		$scope.items = [];
			$scope.pages = 5;
	    	$scope.page = 1 ;
	    	$scope.pageList = [1];
	    	$scope.selPage = 1;
	    	$scope.totalNums = 0;
	    	$scope.selectPage2 = function (page) {
					//不能小于1大于最大
					//if (page < 1 || page > $scope.pages) return;
					//最多显示分页数5
					if (page > 2) {
					//因为只显示5个页数，大于2页开始分页转换
					var newpageList = [];
					for (var i = (page - 3) ; i < ((page + 2) > $scope.pages ? $scope.pages : (page + 2)) ; i++) {
					newpageList.push(i + 1);
					}
					$scope.pageList = newpageList;
					}
					$scope.selPage = page;
					$scope.setData();
					$scope.isActivePage(page);
					console.log("选择的页：" + page);
					$scope.getAllDatas();
				};
				//设置当前选中页样式
				$scope.isActivePage2 = function (page) {
					return $scope.selPage == page;
				};
				//上一页
				$scope.Previous2 = function () {
					if( $.inArray($scope.selPage - 1, $scope.pageList) == -1 ){
						return;
					}
					$scope.selectPage2($scope.selPage - 1);
				}
				//下一页
				$scope.Next2 = function () {
					if( $.inArray($scope.selPage + 1, $scope.pageList) == -1 ){
						return;
					}
					$scope.selectPage2($scope.selPage + 1);
				};
		
		$scope.start_time = '';
		$scope.end_time = '';
		//查询所有操作信息
		$scope.getAllDatas = function(){
			$scope.items = [];
					var postData = {
		    			'cardChipNo':$scope.cardInfor,
						'userName':$scope.myName,
						'cardTypeId':$scope.cardKindId,//卡类型
						'type': parseInt($scope.operationTypeId) ,//操作类型
						'sDate':$scope.start_time,
						'eDate':$scope.end_time,
						'currentPage':$scope.selPage,//页
		    		};	
				console.log(postData);
	    		$scope.getJson($scope.zhaopath+'/localserv/v1/query/cardopt',postData,"POST",function(data){
		   			console.log(data);
		   			if( data.code == 0){
		   				if(data.data.result == null ||   data.data.result.length == 0 ){
		   					$scope.showError('未查询到相关信息');
		   					return;
		   				}
		   				$scope.totalNums = data.data.total ;
		   				$scope.pages = Math.ceil(data.data.total / 10 ); //分页数
						$scope.newPages = $scope.pages > 5 ? 5 : $scope.pages;
						$scope.pageList = [];
						//分页要repeat的数组
						for (var i = 0; i < $scope.newPages; i++) {
							$scope.pageList.push(i + 1);
						}
		   				$scope.operationRecordInfors = data.data.result;
		   				$scope.items = data.data.result;
		   			}else{
		   				$scope.showError(data.msg);
		   			}
		   		});
		}
		//点击查询
		$scope.search = function(){
			$scope.selPage = 1;
			console.log($scope.cardInfor);//卡号
			console.log($scope.myName);//姓名
			console.log($scope.searchDate);//日期
			var str = $scope.searchDate ;
			$scope.start_time = str.substr(0,10) ;
			$scope.end_time = str.substr(13,10)
			console.log($scope.start_time);
			console.log($scope.end_time);
			console.log($scope.operationTypeId);//操作类型
			$scope.getAllDatas();
		}
           //选中某行后获取该行信息
			$scope.operatorSelected = function(event){
	    		event.stopPropagation();
	    		//将数据展示区域的所有td背景颜色先去掉
	    		var allTd = document.getElementById('selectOperator').getElementsByTagName('td');
	    		for(var i = 0;i< allTd.length ; i++ ){
	    			allTd[i].className = '';
	    		}
	    		//保证js点击锁定的是tr标签
	    		var target = event.target ;
	    		if( target.nodeName == 'TD'){
	    			target = target.parentNode ;
	    		}
	    		var p = target.children ;
	    		for(var i = 0;i< p.length ; i++ ){
	    			p[i].className = 'selected';
	    		}
	    		$scope.operatorOrderName = p[0].innerHTML;//用户名
	    		$scope.operatorUserName = p[1].innerHTML;//姓名
	    		$scope.operatorMobile = p[2].innerHTML;//手机号
	    		console.log($scope.operatorOrderName);
	    		console.log($scope.operatorUserName);
	    		console.log($scope.operatorMobile);
    	}
    }])
//交易汇总
    .controller('businessCollectCtrl', ['$scope', '$timeout', function ($scope, $timeout) {
    	$(".modal-dialog").draggable();//为模态对话框添加拖拽
        $(".modal").css("overflow", "hidden");//禁止模态对话框的半透明背景滚动
    	$scope.cardKind ='全部类型';
    	//调用数据分页,先设置为空
			$scope.pagination([]);
			$scope.initial = '10';
    	//获取时间(年月日)
        $scope.getNowFormatDate = function() {
		    var date = new Date();
		    var seperator1 = "-";
		    var seperator2 = ":";
		    var month = date.getMonth() + 1;
		    var strDate = date.getDate();
		    if (month >= 1 && month <= 9) {
		        month = "0" + month;
		    }
		    if (strDate >= 0 && strDate <= 9) {
		        strDate = "0" + strDate;
		    }
		    var now = date.getFullYear() + seperator1 + month + seperator1 + strDate;
		    return now;
		}
			$('#reservation').daterangepicker();
			$scope.searchDate = $scope.getNowFormatDate()+' '+'至'+' '+$scope.getNowFormatDate();
			$scope.operationRecordInfors = [];

				$scope.busCollectInfors = [
			        	{"opt_type": '充值',"cash": "","bank_card": "","online_payment": "11111","meal_card": "","total": '11111'},
			        	{"opt_type": '餐补',"cash": "","bank_card": "","online_payment": "","meal_card": "","total": ''},
			        	{"opt_type": '加班餐补',"cash": "","bank_card": "","online_payment": "","meal_card": "23300","total": '23300'},
			        	{"opt_type": '食堂消费',"cash": "","bank_card": "","online_payment": "","meal_card": "","total": ''},
			        	{"opt_type": '其它消费',"cash": "200","bank_card": "","online_payment": "","meal_card": "2300","total": '2500'},
			        	{"opt_type": '核减',"cash": "","bank_card": "","online_payment": "","meal_card": "","total": ''},
			        	{"opt_type": '核加',"cash": "","bank_card": "","online_payment": "","meal_card": "","total": ''},
			        	{"opt_type": '餐补清零',"cash": "","bank_card": "","online_payment": "","meal_card": "","total": ''},
			        	{"opt_type": '退卡',"cash": "","bank_card": "","online_payment": "","meal_card": "","total": ''},
			        	{"opt_type": '提现',"cash": "","bank_card": "","online_payment": "","meal_card": "","total": ''},
			        	{"opt_type": '开卡押金',"cash": "","bank_card": "","online_payment": "","meal_card": "","total": ''},
			        	{"opt_type": '补卡押金',"cash": "","bank_card": "","online_payment": "","meal_card": "","total": ''},
			        	{"opt_type": '退卡押金',"cash": "","bank_card": "","online_payment": "","meal_card": "","total": ''},
			        	{"opt_type": '工本费',"cash": "","bank_card": "","online_payment": "","meal_card": "","total": ''},
			        	{"opt_type": '充值手续费',"cash": "","bank_card": "","online_payment": "","meal_card": "","total": ''},
			        	{"opt_type": '现金餐补',"cash": "","bank_card": "","online_payment": "","meal_card": "","total": ''},
			        	{"opt_type": '合计',"cash": "200","bank_card": "","online_payment": "11111","meal_card": "25600","total": '36911'}
						           ];
						//调用数据分页
						$scope.pagination($scope.busCollectInfors);
		 //选择操作人按钮
           $scope.seleOperator = function(event){	
        	   event.stopPropagation();
        	   $scope.operators	 = [
			            {"selected": '001',"id": "1","orderName": "fuwu_1","userName": "服务员1","mobile": "15840333752"},
			            {"selected": '002',"id": "2","orderName": "fuwu_2","userName": "服务员2","mobile": "15840333752"},
			            {"selected": '006',"id": "6","orderName": "fuwu_3","userName": "服务员3","mobile": "15840333752"}
			            ];
			    //将之前选中的先清空
			    $scope.operatorOrderName = '';
			     $scope.operatorUserName = '';
			      $scope.operatorMobile = '';
        	   //显示、隐藏窗口
        	   $("#selectOperator").modal('toggle')	
           }
           //选中某行后获取该行信息
			$scope.operatorSelected = function(event){
	    		event.stopPropagation();
	    		//将数据展示区域的所有td背景颜色先去掉
	    		var allTd = document.getElementById('selectOperator').getElementsByTagName('td');
	    		for(var i = 0;i< allTd.length ; i++ ){
	    			allTd[i].className = '';
	    		}
	    		//保证js点击锁定的是tr标签
	    		var target = event.target ;
	    		if( target.nodeName == 'TD'){
	    			target = target.parentNode ;
	    		}
	    		var p = target.children ;
	    		for(var i = 0;i< p.length ; i++ ){
	    			p[i].className = 'selected';
	    		}
	    		
	    		$scope.operatorOrderName = p[0].innerHTML;//用户名
	    		$scope.operatorUserName = p[1].innerHTML;//姓名
	    		$scope.operatorMobile = p[2].innerHTML;//手机号
	    		
	    		console.log($scope.operatorOrderName);
	    		console.log($scope.operatorUserName);
	    		console.log($scope.operatorMobile);
    	}
			//确定选择某操作员
			$scope.trueSelectOperator = function(){
				console.log(666);
				console.log($scope.operatorUserName);
				if( $scope.operatorUserName == ''){
					$('#contentHtml').html('请选择操作员');
					$('#warningChoose').modal('toggle');
					return;
				}
				//$('#operatorText').text($scope.operatorUserName);
				$scope.cardInfor = $scope.operatorUserName ;
				 //显示、隐藏窗口
        	   $("#selectOperator").modal('toggle')
			}
			//清空选中的操作员
			$scope.clearSelectOperator = function(){
				$scope.cardInfor = '';
			}
		//实时监控搜索框的值
            $scope.$watch('cardInfor',  function() {
            	if($scope.cardInfor ==undefined){
            		$scope.cardInfor = '';
            	}
            	console.log($scope.cardInfor);
            	console.log($scope.cardKind);
		           //准备一个空的数组
		           var newList = [];
		           var arr = $scope.operationRecordInfors ;
		           var length = arr.length;
		           if($scope.cardKind =='全部类型' ){
			           	for(var i=0;i<length;i++){
							if( arr[i].opt_user.indexOf($scope.cardInfor) >= 0 ){
								newList.push(arr[i]);
							}
			           }
		           }else{
			           	for(var i=0;i<length;i++){
							if(  (arr[i].opt_user.indexOf($scope.cardInfor) >= 0 )
								  && arr[i].opt_type == $scope.cardKind	){
								newList.push(arr[i]);
							}
			           }
		           }
		           $scope.pagination(newList);
            
            });
            
            //实时监控饭卡类型cardKind
            $scope.$watch('cardKind',  function() {
            	if($scope.cardInfor ==undefined){
            		$scope.cardInfor = '';
            	}
            	console.log($scope.cardKind);
		           //准备一个空的数组
		           var newList = [];
		           var arr = $scope.operationRecordInfors ;
		           var length = arr.length;
		          if($scope.cardKind =='全部类型' ){
			           	for(var i=0;i<length;i++){
							if( arr[i].opt_user.indexOf($scope.cardInfor) >= 0 ){
								newList.push(arr[i]);
							}
			           }
		           }else{
			           	for(var i=0;i<length;i++){
							if(  (arr[i].opt_user.indexOf($scope.cardInfor) >= 0 )
								  && arr[i].opt_type == $scope.cardKind	){
								newList.push(arr[i]);
							}
			           }
		           }
		           $scope.pagination(newList);
            });
    }])
	//消费记录
    .controller('mealCardAuditCtrl', ['$scope', '$timeout', function ($scope, $timeout) {
    	$(".modal-dialog").draggable();//为模态对话框添加拖拽
        $(".modal").css("overflow", "hidden");//禁止模态对话框的半透明背景滚动
        $('#reservation').daterangepicker();
		$scope.searchDate = $scope.getNowFormatDate()+' '+'至'+' '+$scope.getNowFormatDate();
		var allCardType = [{'key':'-1','name':'全部卡类型'}];
			var allopType = [{'key':'-1','name':'全部操作类型'}];
	   	//查询卡型信息
    		$scope.getJson($scope.zhaopath+'/localserv/v1/query/cardkind','',"GET",function(data){
	   			console.log(data);
	   			$scope.cardTypes = allCardType.concat(data.data);
	   			$scope.cardKindId = $scope.cardTypes[0].id ;
	   			$scope.deposit = $scope.cardTypes[0].deposit ; //对应押金
	   		});
    	$scope.cardInfor = '';
    	$scope.myName = '';
    	//获取时间(年月日)
        $scope.getNowFormatDate = function() {
		    var date = new Date();
		    var seperator1 = "-";
		    var seperator2 = ":";
		    var month = date.getMonth() + 1;
		    var strDate = date.getDate();
		    if (month >= 1 && month <= 9) {
		        month = "0" + month;
		    }
		    if (strDate >= 0 && strDate <= 9) {
		        strDate = "0" + strDate;
		    }
		    var now = date.getFullYear() + seperator1 + month + seperator1 + strDate;
		    
		    return now;
		}
		$scope.items = [];
		$scope.initial = 10;
		$scope.totalNums = 0;
		$scope.items = [];
			$scope.pages = 5;
	    	$scope.page = 1 ;
	    	$scope.pageList = [1];
	    	$scope.selPage = 1;
	    	$scope.totalNums = 0;
	    	$scope.selectPage2 = function (page) {
					//不能小于1大于最大
					//if (page < 1 || page > $scope.pages) return;
					//最多显示分页数5
					if (page > 2) {
					//因为只显示5个页数，大于2页开始分页转换
					var newpageList = [];
					for (var i = (page - 3) ; i < ((page + 2) > $scope.pages ? $scope.pages : (page + 2)) ; i++) {
					newpageList.push(i + 1);
					}
					$scope.pageList = newpageList;
					}
					$scope.selPage = page;
					$scope.setData();
					$scope.isActivePage(page);
					console.log("选择的页：" + page);
					$scope.getAllDatas();
				};
				//设置当前选中页样式
				$scope.isActivePage2 = function (page) {
					return $scope.selPage == page;
				};
				//上一页
				$scope.Previous2 = function () {
					if( $.inArray($scope.selPage - 1, $scope.pageList) == -1 ){
						return;
					}
					$scope.selectPage2($scope.selPage - 1);
				}
				//下一页
				$scope.Next2 = function () {
					if( $.inArray($scope.selPage + 1, $scope.pageList) == -1 ){
						return;
					}
					$scope.selectPage2($scope.selPage + 1);
				};
				
		//查询所有信息
		$scope.getAllDatas = function(){
			$scope.items = [];
					var postData = {
		    			'cardChipNo':$scope.cardInfor,
						'userName':$scope.myName,
						'cardTypeId':$scope.cardKindId,//卡类型
						'sDate':$scope.start_time,
						'eDate':$scope.end_time,
						'currentPage':$scope.selPage,//页
		    		};	
				console.log(postData);
	    		$scope.getJson($scope.zhaopath+'/localserv/v1/query/cardcost',postData,"POST",function(data){
		   			console.log(data);
		   			if( data.code == 0){
		   				if(data.data.result == null ||   data.data.result.length == 0 ){
		   					$scope.showError('未查询到相关信息');
		   					return;
		   				}
		   				$scope.totalNums = data.data.total ;
		   				$scope.pages = Math.ceil(data.data.total / 10 ); //分页数
						$scope.newPages = $scope.pages > 5 ? 5 : $scope.pages;
						$scope.pageList = [];
						//分页要repeat的数组
						for (var i = 0; i < $scope.newPages; i++) {
							$scope.pageList.push(i + 1);
						}
		   				$scope.operationRecordInfors = data.data.result;
		   				$scope.items = data.data.result;
		   			}else{
		   				$scope.showError(data.msg);
		   			}
		   		});
		}
		$scope.getAllDatas();
		
        //点击查询按钮
		$scope.search = function(){
			$scope.selPage = 1;
			console.log($scope.cardInfor);//卡号
			console.log($scope.myName);//姓名
			console.log($scope.searchDate);//日期
			var str = $scope.searchDate ;
			$scope.start_time = str.substr(0,10) ;
			$scope.end_time = str.substr(13,10)
			console.log($scope.start_time);
			console.log($scope.end_time);
			$scope.getAllDatas();
		}
    	
    }])
    
    //餐卡类型
    .controller('mealCardTypeCtrl', ['$scope', '$timeout', function ($scope, $timeout) {
    	$(".modal-dialog").draggable();//为模态对话框添加拖拽
        $(".modal").css("overflow", "hidden");//禁止模态对话框的半透明背景滚动
    	$scope.cardInfor = '';
    	$scope.cardKindId = '';
    	$scope.mealCardInfors = [];
    	$scope.intialDatas = [];
		//进入页面自动查询卡型信息
		$scope.getAllCardKindTypes = function(){
			$scope.getJson($scope.resultPath+'/wisdomeatery/v1/cardControl/canteen/'+$scope.canteenId+'/getAllCardTypes','',"GET",function(data){
	   			console.log(data);
	   			$scope.mealCardInfors = data.data;
	   			$scope.intialDatas = data.data;
	   			$scope.cardKindId = '';
	   		});
		}
		
   		if( $scope.getCanteenId() != ''){
	   			$scope.canteenId =  $scope.getCanteenId() ;
	   			$scope.getAllCardKindTypes();
   			}
	   	$scope.$on('to-child', function(event,data) {
	   		 //获取从父控制器传来的当前选中食堂
						$scope.canteenId = data;
	   				$scope.getAllCardKindTypes();
			});
   		
           //选中某行后获取该行信息
			$scope.itemSelected = function(event){
	    		event.stopPropagation();
	    		//将数据展示区域的所有td背景颜色先去掉
	    		var allTd = document.getElementById('dataList').getElementsByTagName('td');
	    		for(var i = 0;i< allTd.length ; i++ ){
	    			allTd[i].className = '';
	    		}
	    		//保证js点击锁定的是tr标签
	    		var target = event.target ;
	    		if( target.nodeName == 'TD'){
	    			target = target.parentNode ;
	    		}
	    		if( target.nodeName == 'A'){
	    			target = target.parentNode.parentNode ;
	    		}
	    		if( target.nodeName == 'I'){
	    			target = target.parentNode.parentNode.parentNode ;
	    		}
	    		var p = target.children ;
	    		for(var i = 0;i< p.length ; i++ ){
	    			p[i].className = 'selected';
	    		}
	    		$scope.cardKindId = p[0].innerHTML;//卡类型id
	    		$scope.cardTypeName = p[1].innerHTML;//类型名称
	    		$scope.perMoneyMonth =  parseFloat(p[2].innerHTML)   ;//月补金额
	    		$scope.useMoneyLimitDay = parseFloat(p[3].innerHTML);//每日限额
	    		$scope.overDraftLine = parseFloat(p[4].innerHTML);//透支额度
	    		$scope.deposit = parseFloat(p[5].innerHTML);//押金
	    		$scope.isTempPosted = p[6].innerHTML;//是否为临时卡
   			 }
			
			$scope.isTemp = false;
			$scope.isTempPosted = 0;
			//打开新增卡类型模板
			$scope.openAddModal = function(){
				 $scope.cardTypeName = '';
				 $scope.perMoneyMonth = 0;
				 $scope.useMoneyLimitDay = 0;
				 $scope.overDraftLine = 0;
				 $scope.deposit = 0;
				 $scope.isTemp = false;
				
				 $("#addCardType").modal('toggle');
			}
			//类型新增模板确定键
			$scope.addType_true = function(){
				
					if( $scope.isTemp){
						$scope.isTempPosted = 1;
					}else{
						$scope.isTempPosted = 0;
					}
					
					if( isNull($scope.cardTypeName) ){
						$scope.showError('类型名称不能为空');
						return;
					}
					if( $scope.cardTypeName.length > 10 ){
						$scope.showError('类型名称长度不得大于10位');
						return;
					}
					if( isNull($scope.perMoneyMonth+'') ){
						$scope.showError('月补金额不能为空');
						return;
					}
					if( checkDouble( $scope.perMoneyMonth+'' ) ){
						$scope.showError('月补金额只能为最多两位小数的正数');
						return;
					}
					if( isNull($scope.useMoneyLimitDay+'') ){
						$scope.showError('每日限额不能为空');
						return;
					}
					if( checkDouble( $scope.useMoneyLimitDay+'' ) ){
						$scope.showError('每日限额只能为最多两位小数的正数');
						return;
					}
					if( isNull($scope.overDraftLine+'') ){
						$scope.showError('透支额度不能为空');
						return;
					}
					console.log($scope.overDraftLine);
					if( checkDouble( $scope.overDraftLine+'' ) ){
						$scope.showError('透支额度只能为最多两位小数的正数');
						return;
					}
					if( isNull($scope.deposit+'') ){
						$scope.showError('押金不能为空');
						return;
					}
					if( !isNumber($scope.deposit+'') ){
						$scope.showError('押金必须为正整数');
						return;
					}
					if( $scope.perMoneyMonth >= 10000 ){
						$scope.showError('月补金额应小于10000');
						return;
					}
					if( $scope.useMoneyLimitDay >= 10000 ){
						$scope.showError('每日限额应小于10000');
						return;
					}
					if( $scope.overDraftLine >= 10000 ){
						$scope.showError('透支额度应小于10000');
						return;
					}
					if( $scope.deposit >= 1000 ){
						$scope.showError('押金应小于1000');
						return;
					}
				var postData = {
					'name':$scope.cardTypeName,
					'perMoneyMonth':$scope.perMoneyMonth,
					'useMoneyLimitDay':$scope.useMoneyLimitDay,
					'overDraftLine':$scope.overDraftLine,
					'deposit':$scope.deposit,
					'isTemp': $scope.isTempPosted,
					
				}
				$scope.getJson($scope.resultPath+'/wisdomeatery/v1/cardControl/canteen/'+$scope.canteenId+'/addCardType',postData,"POST",function(data){
		   			console.log(data);
		   			if( data.code == 0){
		   				$scope.showSuccess('操作成功！');
		   				//成功后重新查询卡类型
		   				$scope.getAllCardKindTypes();
		   				 $("#addCardType").modal('toggle');
		   			}else{
		   				$scope.showError(data.msg);
		   			}
		   		});
			}
			//打开卡类型维护模板
			$scope.openupdateModal = function(){
				if( $scope.cardKindId == ''){
					$scope.showError('请选择卡类型');
					return;
				}
				
				if( $scope.isTempPosted == '否'){
					$scope.isTemp = false;
				}else{
					$scope.isTemp = true;
				}
				console.log($scope.isTempPosted);
				console.log($scope.isTemp);
				$("#updateCardType").modal('toggle');
			}
			//修改类型模板确定键
			$scope.updateType_true = function(){
				if( $scope.isTemp){
						$scope.isTempPosted = 1;
					}else{
						$scope.isTempPosted = 0;
					}
					
					if( isNull($scope.cardTypeName) ){
						$scope.showError('类型名称不能为空');
						return;
					}
					if( $scope.cardTypeName.length > 10 ){
						$scope.showError('类型名称长度不得大于10位');
						return;
					}
					if( isNull($scope.perMoneyMonth+'') ){
						$scope.showError('月补金额不能为空');
						return;
					}
					if( checkDouble( $scope.perMoneyMonth+'' ) ){
						$scope.showError('月补金额只能为最多两位小数的正数');
						return;
					}
					if( isNull($scope.useMoneyLimitDay+'') ){
						$scope.showError('每日限额不能为空');
						return;
					}
					if( checkDouble( $scope.useMoneyLimitDay+'' ) ){
						$scope.showError('每日限额只能为最多两位小数的正数');
						return;
					}
					if( isNull($scope.overDraftLine+'') ){
						$scope.showError('透支额度不能为空');
						return;
					}
					if( checkDouble( $scope.overDraftLine+'' ) ){
						$scope.showError('透支额度只能为最多两位小数的正数');
						return;
					}
					if( isNull($scope.deposit+'') ){
						$scope.showError('押金不能为空');
						return;
					}
					if( !isNumber($scope.deposit+'') ){
						$scope.showError('押金必须为正整数');
						return;
					}
					if( $scope.perMoneyMonth >= 10000 ){
						$scope.showError('月补金额应小于10000');
						return;
					}
					if( $scope.useMoneyLimitDay >= 10000 ){
						$scope.showError('每日限额应小于10000');
						return;
					}
					if( $scope.overDraftLine >= 10000 ){
						$scope.showError('透支额度应小于10000');
						return;
					}
					if( $scope.deposit >= 1000 ){
						$scope.showError('押金应小于1000');
						return;
					}
					
				var postData = {
					'name':$scope.cardTypeName,
					'perMoneyMonth':$scope.perMoneyMonth,
					'useMoneyLimitDay':$scope.useMoneyLimitDay,
					'overDraftLine':$scope.overDraftLine,
					'deposit':$scope.deposit,
					'isTemp': $scope.isTempPosted,
				}
				console.log(postData);
				console.log($scope.cardKindId);
				$scope.getJson($scope.resultPath+'/wisdomeatery/v1/cardControl/canteen/'+$scope.canteenId+'/updateCardType/'+$scope.cardKindId,postData,"PUT",function(data){
		   			console.log(data);
		   			if( data.code == 0){
		   				$scope.showSuccess('操作成功！');
		   				//成功后重新查询卡类型
		   				$scope.getAllCardKindTypes();
		   				$("#updateCardType").modal('toggle');
		   			}else{
		   				$scope.showError(data.msg);
		   			}
		   		});
			}
			
				//实时监控搜索框的值
            $scope.$watch('cardInfor',  function() {
            	if($scope.cardInfor ==undefined){
            		$scope.cardInfor = '';
            	}
            	console.log($scope.cardInfor);
		           //准备一个空的数组
		           var newList = [];
		           var arr = $scope.intialDatas ;
		           var length = arr.length;
			           	for(var i=0;i<length;i++){
							if(  arr[i].name.indexOf($scope.cardInfor) >= 0 ){
								newList.push(arr[i]);
							}
			           }
			           	
            		$scope.mealCardInfors = newList.concat();
            });
			
			
			
			//  	//获取部门信息
//		$scope.depts=[];
//		$scope.department = function() {
//			var path =$scope.resultPath+"/wisdomeatery/v1/base_system/departments"
//			$scope.getJson(path,'',"get",function(data){
//				console.log(data);
//			})
//		}
//		$scope.department();
			//展开部门权限维护栏
//			$scope.edit = function(cardKindId){
//				console.log(cardKindId);
//				$scope.cardKindId = cardKindId ;
//				//查看此卡已经有哪些部门权限
//				$scope.getJson($scope.resultPath+'/wisdomeatery/v1/query/cardkinds/'+$scope.cardKindId+"/departments",'',"GET",function(data){
//		   			console.log(data);
//		   			$scope.canteens = data.data;
//		   			$scope.depts = $scope.canteens[0].departments ;
//		   		});
//				  $("#relationDepartment").modal('toggle')
//			}
//			$scope.getDepartments = function(event,canteenId){
//				var target = event.target ;
//	   			$(target).siblings().each(function(){
//	   				$(this).css('background-color','#ffffff');
//	   			});
//	   			$(target).css('background-color','#e4eaec');
//				var arr = $scope.canteens ;
//				for( var i= 0 ; i<arr.length ; i ++){
//					if(arr[i].canteen_id == canteenId){
//						$scope.depts = $scope.canteens[i].departments ;
//					}
//				}
//			}
//			//关联部门展开确定键
//			$scope.relationDept_true = function(){
//				$scope.getJson($scope.resultPath+'/wisdomeatery/v1/query/cardkinds/'+$scope.cardKindId+"/departments",$scope.canteens,"PUT",function(data){
//		   			console.log(data);
//		   			if( data.code == 0){
//		   				$scope.showSuccess('操作成功！');
//		   				$("#relationDepartment").modal('toggle');
//		   			}else{
//		   				$scope.showError(data.msg);
//		   			}
//		   		});
//				
//			}
		
    	
    }])

